package com.dragon.repository.mapper;

import com.dragon.repository.entity.AdminDepartment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dragon.repository.entity.Department;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户部门表 Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-06-12
 */
@Mapper
public interface AdminDepartmentMapper extends BaseMapper<AdminDepartment> {

    @Select("SELECT B.* FROM dragon_admin_department A Join dragon_department on A.department_id = B.id WHERE A.admin_id = #{id}")
    Department selectDepartmentByAdminId(Integer id);

    @Select("<script>" +
            "select dad.* from dragon_admin_department dad " +
            "left join dragon_admin da on dad.admin_id = da.id " +
            "where da.deleted = 0" +
            "<if test='departmentIds.size != 0 and departmentIds != \"\"'> "+
            " and dad.department_id in " +
            "<foreach collection = 'departmentIds' item = 'item' open = '(' close = ')' separator = ','>" +
            "#{item}" +
            "</foreach>" +
            "</if>" +
            "</script>")
    List<AdminDepartment> selectAdminDepartmentByDepartmentIds(List<Integer> departmentIds);
}
